package com.uplooking.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.springframework.util.Base64Utils;

public class FileUtils {

	public static String encode(String filepath) throws IOException{
		InputStream in  = new FileInputStream(filepath);
		byte[] b = new byte[in.available()];
		in.read(b);
		in.close();
		return Base64Utils.encodeToString(b);
	}
	
	public static void decode(String text,OutputStream os) throws IOException{
		byte[] b = Base64Utils.decodeFromString(text);
		os.write(b);
		os.flush();
		os.close();
	}

}
